/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package muddb.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;


/**
 *
 * @author keith
 */
@Entity
@Table( name = "mud_place" )
@NamedQueries( {
  @NamedQuery( name = "MudPlace.findByPlaceId",
                query = "SELECT m FROM MudPlace m WHERE m.placeId = :placeId" ),
  @NamedQuery( name = "MudPlace.findByPlaceName",
                query = "SELECT m FROM MudPlace m WHERE m.placeName = :placeName" ),
  @NamedQuery( name = "MudPlace.findByShortDescr",
                query = "SELECT m FROM MudPlace m WHERE m.shortDescr = :shortDescr" ),
  @NamedQuery( name = "MudPlace.findByLongDescr",
                query = "SELECT m FROM MudPlace m WHERE m.longDescr = :longDescr" ) } )
public class MudPlace implements Serializable {
  private static final long serialVersionUID = 1L;
  private Integer placeId;
  private String placeName;
  private String shortDescr;
  private String longDescr;
  private Collection<UserChar> userCharCollection;
  private Collection<MudPortal> mudPortalEndCollection;
  private Collection<MudPortal> mudPortalStartCollection;


  public MudPlace() {
  }


  public MudPlace( Integer placeId ) {
    this.placeId = placeId;
  }


  public MudPlace( Integer placeId, String placeName, String shortDescr ) {
    this.placeId = placeId;
    this.placeName = placeName;
    this.shortDescr = shortDescr;
  }


  @Id
  @GeneratedValue( strategy=GenerationType.SEQUENCE )
  @Column( name = "place_id", nullable = false )
  public Integer getPlaceId() {
    return placeId;
  }


  public void setPlaceId( Integer placeId ) {
    this.placeId = placeId;
  }


  @Column( name = "place_name", nullable = false, length = 50, unique=true )
  public String getPlaceName() {
    return placeName;
  }


  public void setPlaceName( String placeName ) {
    this.placeName = placeName;
  }


  @Column( name = "short_descr", nullable = false, length = 80 )
  public String getShortDescr() {
    return shortDescr;
  }


  public void setShortDescr( String shortDescr ) {
    this.shortDescr = shortDescr;
  }


  @Column( name = "long_descr", length = 1024 )
  public String getLongDescr() {
    return longDescr;
  }


  public void setLongDescr( String longDescr ) {
    this.longDescr = longDescr;
  }


  @JoinTable( name = "user_char_loc",
    joinColumns = {
        @JoinColumn( name = "place_id", referencedColumnName = "place_id" ) },
    inverseJoinColumns = {
        @JoinColumn( name = "user_id", referencedColumnName = "user_id" ),
        @JoinColumn( name = "char_id", referencedColumnName = "char_id" ) } )
  @OneToMany
  public Collection<UserChar> getUserCharCollection() {
    return userCharCollection;
  }


  public void setUserCharCollection( Collection<UserChar> userCharCollection ) {
    this.userCharCollection = userCharCollection;
  }


  @OneToMany( cascade = CascadeType.ALL, mappedBy = "endPlace" )
  public Collection<MudPortal> getMudPortalEndCollection() {
    return mudPortalEndCollection;
  }


  public void setMudPortalEndCollection( Collection<MudPortal> mudPortalEndCollection ) {
    this.mudPortalEndCollection = mudPortalEndCollection;
  }


  @OneToMany( cascade = CascadeType.ALL, mappedBy = "startPlace" )
  public Collection<MudPortal> getMudPortalStartCollection() {
    return mudPortalStartCollection;
  }


  public void setMudPortalStartCollection( Collection<MudPortal> mudPortalStartCollection ) {
    this.mudPortalStartCollection = mudPortalStartCollection;
  }


  @Override
  public int hashCode() {
    int hash = 0;
    hash += ( placeId != null ? placeId.hashCode() : 0 );
    return hash;
  }


  @Override
  public boolean equals( Object object ) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if ( !( object instanceof MudPlace ) ) {
      return false;
    }
    MudPlace other = (MudPlace) object;
    if ( ( this.placeId == null && other.placeId != null ) || ( this.placeId != null && !this.placeId.equals( other.placeId ) ) ) {
      return false;
    }
    return true;
  }


  @Override
  public String toString() {
    return "muddb.entities.MudPlace[placeId=" + placeId + "]";
  }


  public void addEnd( MudPortal aThis ) {
    if ( mudPortalEndCollection == null ){
      mudPortalEndCollection = new ArrayList<MudPortal>();
    }
    mudPortalEndCollection.add( aThis );
  }


  public void addStart( MudPortal aThis ) {
    if ( mudPortalStartCollection == null ){
      mudPortalStartCollection = new ArrayList<MudPortal>();
    }
    mudPortalStartCollection.add( aThis );
  }

}
